package com.heima.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

@Slf4j
@Component    //把处理器组件加到IOC容器中
public class MyDateObjectHandler implements MetaObjectHandler {

    /*数据库添加操作自动填充*/
    @Override
    public void insertFill(MetaObject metaObject) {
        /*log.info("公共字段自动填充insert");*/
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
//        metaObject.setValue("createUser", BaseContext.getCurrentID());
//        metaObject.setValue("updateUser", BaseContext.getCurrentID());

    }

    /*数据库修改操作自动填充*/
    @Override
    public void updateFill(MetaObject metaObject) {
        /* log.info("公共字段自动填充update");*/
        metaObject.setValue("updateTime", LocalDateTime.now());
//        metaObject.setValue("updateUser", BaseContext.getCurrentID());
    }

}
